package offer;

/**
 * <p>
 * 剑指 Offer 52. 两个链表的第一个公共节点
 * </p>
 *
 * @author xiaozuolin
 * @date 2021/9/28 17:07
 */
public class Offer52 {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode A = headA;
        ListNode B = headB;
        while (A != B) {
            A = A != null ? A.next : headB;
            B = B != null ? B.next : headA;
        }
        return A;
    }
}
